package design.proxy;

public class ProxyTest {
    public static void main(String[] args) {
        Proxy proxy = new Proxy(new RealSubject());
        proxy.Request();
    }
}

//抽象-处理目标
interface Subject {
    void Request();
}
//真实-处理目标
class RealSubject implements Subject {
    @Override
    public void Request() {
        System.out.println("访问真实主题方法...");
    }
}

//代理
class Proxy implements Subject {
    private RealSubject realSubject;
    // 构造方法
    public Proxy(RealSubject realSubject) {
        this.realSubject = realSubject;
    }
    @Override
    public void Request() {
        preRequest();
        realSubject.Request();
        postRequest();
    }
    public void preRequest() { // 代理前置
        System.out.println("访问真实主题之前的预处理。");
    }
    public void postRequest() { // 代理后置
        System.out.println("访问真实主题之后的后续处理。");
    }
}